/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.pedagogue.examination;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.letmeshare.pedagogue.core.entities.Party;
import org.letmeshare.pedagogue.core.validation.ValidationException;
import org.letmeshare.pedagogue.core.validation.Validator;

/**
 *
 * @author aby
 */
@Entity
public class Result implements Serializable,Validator {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String id;
    @ManyToOne
    private Party candidate;
    @ManyToOne
    private Party createdBy;
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;
    private boolean  isPassed;
    private float  scorepercentage;
    
    @ManyToOne
    private Examination examination;
    

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Result)) {
            return false;
        }
        Result other = (Result) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.letmeshare.pedagogue.examination.Result[ id=" + id + " ]";
    }

    public Party getCandidate() {
        return candidate;
    }

    public Party getCreatedBy() {
        return createdBy;
    }

    public Date getCreated() {
        return created;
    }

    public float getScorepercentage() {
        return scorepercentage;
    }

    public Examination getExamination() {
        return examination;
    }

    public void setCandidate(Party candidate) {
        this.candidate = candidate;
    }

    public void setCreatedBy(Party createdBy) {
        this.createdBy = createdBy;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public void setScorepercentage(float scorepercentage) {
        this.scorepercentage = scorepercentage;
    }

    public void setExamination(Examination examination) {
        this.examination = examination;
    }

    public void validate() throws ValidationException {
       if(scorepercentage<0 ||scorepercentage>100){
           throw new ValidationException("Invalid percentage");
       }
    }
    
}
